var file;
// Deselect selected entity
with(ToolEntityMorpher){event_user(15);}

// Clear the board
with(Entity){if (entity!=noone){instance_destroy();}}
with(Component){instance_destroy();}

filename=argument0;
file = file_text_open_read(filename);
LoadFile = file;
loadedEntities = false;
loadedLesson = false;

// Read file
while(!loadedLesson)
{
    tag = readLine();
    switch(tag.name)
    {
        case "system":
            loadSystem();
        break;
    }
    nextLine();
    if (file_text_eof(LoadFile))
    {
        loadedLesson = true;
    }
}

readLine();
readLine();
readLine();


with(TagData){instance_destroy();}

/*
while(!loadedEntities)
{
    readLine();
    // write stuff to load entities (instance_create(), etc)
    _eid = findEntityById(readLine());
    _artsprite = sprite_get_index(readLine());
    _x = real(readLine());
    _y = real(readLine());
    _imageangle = real(readLine());
    readLine();
    ins = instance_create(_x, _y, Entity);
    ins.sprite_index = _artsprite;
    ins.image_angle = _imageangle;
    if (_eid != noone)
    {
        ins.entity = _eid;
    }
    if (peekLineTag()=='</entities>')
    {
        show_message("finished loading entities");
        loadedEntities = true;
    }
}
readLine();
readLine();
for(i=0;i<instance_number(Component);i+=1)
{
    ii = instance_find(Component, i);
    switch(ii.type)
    {
        case "question_multi":
            if (ii.object_index == QuestionMultiChoice)
            {
                readLine('<component sprite="'+ sprite_get_name(ii.sprite_index) +'">');
                readLine('<x>' + string(ii.x) + '</x>');
                readLine('<y>' + string(ii.y) + '</y>');
                readLine('<width>' + string(ii.width) + '</width>');
                readLine('<height>' + string(ii.height) + '</height>');
                readLine('<rotation>' + string(ii.image_angle) + '</rotation>');
                readLine('<question name="' + ii.question + '">');
                readAnswers(ii);
                readLine('</question>');
                readLine('<behaviour>');
                readEvents(ii);
                readLine('</behaviour>');
                readLine("</component>");
            }
        break;
    }
}
readLine("</components>");
readLine("</system>");
*/
file_text_close(file);
